<template>
  <!-- 头部 -->
  <div class="header">
    <div class="header-left">
      中东地区
      <van-icon name="arrow" />
    </div>
    <van-search v-model="search" placeholder="请输入搜索关键词" shape="round" />
  </div>
  <!-- 轮播图 -->
  <!-- div.my-swiper -->
  <van-swipe
    class="my-swiper"
    height="170"
    :autoplay="3000"
    indicator-color="white"
  >
    <van-swipe-item v-for="item in initData.slides" :key="item.id">
      <van-image radius="10" :src="item.pic_image_url" />
    </van-swipe-item>
  </van-swipe>
  <!-- 中间图片快捷入口 -->
  <van-row justify="space-around">
    <van-col
      span="12"
      v-for="(item, index) in initData.nav2s"
      :key="item.id"
      @click="clickNav2s(index)"
    >
      <van-image radius="10" style="padding: 0 5px" :src="item.pic_image_url" />
    </van-col>
  </van-row>
  <!-- 中间多个按钮 -->
  <van-row justify="space-around" style="margin: 5px">
    <van-col
      style="width: 20%"
      v-for="(item, index) in initData.navs"
      :key="item.id"
      @click="clickNavs(index)"
    >
      <div class="navs_outer">
        <van-image radius="10" style="width: 95%" :src="item.pic_image_url" />
        <p>{{ item.title }}</p>
      </div>
    </van-col>
  </van-row>
  <!-- 医院列表 -->
  <van-row
    class="yy-list"
    justify="space-around"
    v-for="(item, index) in initData.hospitals"
    :key="item.id"
    @click="clickHosList(item)"
  >
    <van-col span="6">
      <van-image radius="10" height="100" width="90" :src="item.avatar_url" />
    </van-col>

    <van-col span="15" class="yy">
      <div class="yy-name">
        {{ item.name }}
      </div>
      <div class="yy-type">
        <span>{{ item.rank }}</span>
        &nbsp;
        <span>{{ item.label }}</span>
      </div>
      <div class="yy-text">
        {{ item.intro }}
      </div>
    </van-col>
  </van-row>
</template>

<script setup>
import { onMounted, reactive, ref } from "vue";
import { indexData } from "../../api";
import { useRouter } from "vue-router";

onMounted(() => {
  indexData().then(({ data }) => {
    if (data.code === 10000) {
      //   console.log(data, "indexData");
      initData.hospitals = data.data.hospitals;
      initData.nav2s = data.data.nav2s;
      initData.navs = data.data.navs;
      initData.now = data.data.now;
      initData.slides = data.data.slides;
      console.log(initData, "home页面初始数据");
    }
  });
});

const router = useRouter();
// 搜索数据
const search = ref("");
// 首页初始化数据
const initData = reactive({
  hospitals: [],
  nav2s: [],
  navs: [],
  now: "",
  slides: [],
});
// 点击快捷图片
const clickNav2s = (index) => {
  // console.log(initData.hospitals[index].id,'index');
  router.push(`/createOrder?id=${initData.hospitals[index].id}`);
};
// 点击navs卡片
const clickNavs = (index) => {
  router.push(`/createOrder?id=${initData.hospitals[index].id}`);
};
//点击医院列表
const clickHosList = (item)=>{
  // console.log(item);
  router.push(`/createOrder?id=${item.id}`);

  
}
</script>

<style lang="less" scoped>
.header {
  display: flex;
  justify-content: space-between;
  margin: 5px;
  line-height: 54px;
  .header-left {
    padding-left: 22px;
    background: url()
      no-repeat left center;
    background-size: 20px;
    font-size: 20px;
    font-weight: bold;
    color: #666666;
  }
}
.my-swiper {
  margin: 5px;
}
.navs_outer {
  // width: auto;
  display: flex;
  flex-direction: column;

  align-items: center;
  p {
    margin: 0;
  }
}
.yy-list {
  padding-bottom: 10px;
  margin: 20px 0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.04), 0 1px 6px 0 rgba(0, 0, 0, 0.04);
  .yy {
    .yy-name {
      font-size: 20px;
      line-height: 30px;
      font-weight: bold;
    }
    .yy-type {
      font-weight: bold;
      line-height: 25px;
      font-size: 15px;
      color: #0ca7ae;
    }
    .yy-text {
      font-size: 14px;
      color: #999999;
    }
  }
}
.bottom-text {
  line-height: 50px;
  text-align: center;
  color: #999999;
}
</style>
